package cn.wolfcode.car.business.web.contorller;

import cn.wolfcode.car.business.domain.ServiceItem;
import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.qo.StatementItemQuery;
import cn.wolfcode.car.business.qo.StatementItemVO;
import cn.wolfcode.car.business.service.IServiceItemService;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/business/statementItem")
public class StatementItemController {

    private static final String prefix = "business/ststementItem/";

    @Autowired
    private IStatementService statementService;

    @Autowired
    private IStatementItemService statementItemService;


    @RequestMapping("/itemDetail")
    public String itemDetail(Model model, Long statementId) {
        Statement statement = statementService.get(statementId);

        model.addAttribute("statement", statement);

        if (Statement.STATUS_CONSUME.equals(statement.getStatus())) {
            return prefix + "editDetail";
        } else {
            return prefix + "showDetail";
        }
    }

    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StatementItem> query(StatementItemQuery statementItemQuery) {
        return statementItemService.query(statementItemQuery);
    }

    @RequestMapping("/saveItems")
    @ResponseBody
    public AjaxResult saveItems(@RequestBody StatementItemVO arr) {
        System.out.println(arr.getStatementId());
        System.out.println(arr.getDiscountAmount());

        statementItemService.saveItem(arr);
        return AjaxResult.success();
    }


    @RequestMapping("/payFun")
    @ResponseBody
    public AjaxResult payFun(Long statementId){
        statementItemService.payFun(statementId);
        return AjaxResult.success();
    }
}
